<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MM.Toolkit"
                    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                    xmlns:kit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
    
    <!-- Icon Licenses -->
    <!-- http://creativecommons.org/licenses/by-sa/3.0/ -->
    <!-- http://creativecommons.org/licenses/by/2.5/ -->
    <!-- http://creativecommons.org/licenses/by/3.0/us/ -->



    <!-- Class Resources -->
    <local:BoxBackgroundConverter x:Key="BoxBackgroundConverter" />
    <local:GridLengthTypeConverter x:Key="GridLengthTypeConverter" />
    <local:DateTimeFormatConverter x:Key="DateTimeFormatConverter" />
    <local:BooleanToVisibilityTypeConverter x:Key="BooleanToVisibilityTypeConverter" />
    <local:PopupShowingImageConverter x:Key="PopupShowingImageConverter" />

    
    
    <!-- Brush Resources -->
    <LinearGradientBrush x:Key="TextBoxBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFA3AEB9" Offset="0"/>
        <GradientStop Color="#FF8399A9" Offset="0.375"/>
        <GradientStop Color="#FF718597" Offset="0.375"/>
        <GradientStop Color="#FF617584" Offset="1"/>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="TextBoxSelectedBorderBrush"
                     Color="#FF6DBDD1" />

    <Style x:Key="TextBoxBorder" TargetType="Border">
        <Setter Property="Background" Value="Wheat" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorderBrush}" />
    </Style>

    <Style x:Key="TextBoxBorderFocused" TargetType="Border">
        <Setter Property="Background" Value="Wheat" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorderBrush}" />
    </Style>



    <!-- ####################################################################### -->
    <!-- #                                                                     # -->
    <!-- #                            DateTimeBox                              # -->
    <!-- #                                                                     # -->
    <!-- ####################################################################### -->
    <Style TargetType="local:DateTimeBox">
        <Setter Property="Width" Value="170" />
        <Setter Property="Height" Value="20" />
        <Setter Property="MinWidth" Value="40" />
        <Setter Property="IsEnabled" Value="True" />
        <Setter Property="Background" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:DateTimeBox">
                    <Border x:Name="PART_LayoutRootBorder"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_InnerGridBorder"
                                                                       Storyboard.TargetProperty="(Border.BorderThickness)"
                                                                       Duration="0">
                                            <ObjectAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="1" />
                                            </ObjectAnimationUsingKeyFrames.KeyFrames>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_InnerGridBorder"
                                                                       Storyboard.TargetProperty="(Border.BorderThickness)"
                                                                       Duration="0">
                                            <ObjectAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="1" />
                                            </ObjectAnimationUsingKeyFrames.KeyFrames>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="PART_LayoutRoot">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid Grid.Column="0">
                                    <Border Background="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=IsReadOnly, Mode=OneWay, Converter={StaticResource BoxBackgroundConverter}, ConverterParameter='invert'}"
                                            Padding="2,2,0,2"
                                            BorderThickness="1"
                                            BorderBrush="{StaticResource TextBoxBorderBrush}" />
                                    <Border x:Name="PART_InnerGridBorder"
                                            Margin="1"
                                            BorderThickness="0"
                                            BorderBrush="{StaticResource TextBoxSelectedBorderBrush}" />
                                    <StackPanel Orientation="Horizontal"
                                                Margin="1">
                                        <TextBox x:Name="PART_DateTextBox"
                                                 Margin="0,1,0,1"
                                                 Padding="1,-1, 1, -1"
                                                 BorderThickness="0" />
                                        <TextBox x:Name="PART_TimeTextBox"
                                                 Margin="0,1,0,1"
                                                 Padding="1,-1, 1, -1"
                                                 BorderThickness="0" />
                                    </StackPanel>
                                </Grid>
                                <Button Grid.Column="1"
                                        Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ShowHideCalendarCommand, Mode=OneWay}"
                                        Width="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Height, Mode=OneWay}"
                                        Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=DateButtonIsVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibilityTypeConverter}}">
                                    <Image Source="/MM.Toolkit;component/Resources/DateTimeBox.Icon.24x24.png" />
                                </Button>
                                <Button Grid.Column="2"
                                        Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ShowHideTimeCommand, Mode=OneWay}"
                                        Width="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Height, Mode=OneWay}"
                                        Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=TimeButtonIsVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibilityTypeConverter}}">
                                    <Image Source="/MM.Toolkit;component/Resources/Clock.24x24.png" />
                                </Button>
                                <Grid Grid.Column="3"
                                      Width="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Height, Mode=OneWay}"
                                      Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=UpDownButtonsIsVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibilityTypeConverter}}">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height=".5*" />
                                        <RowDefinition Height=".5*" />
                                    </Grid.RowDefinitions>
                                    <Button Grid.Row="0"
                                            IsTabStop="False"
                                            Padding="1"
                                            Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=UpCommand, Mode=OneWay}">
                                        <Image Source="/MM.Toolkit;component/Resources/Arrow.Bullet.Up.32x32.png" />
                                    </Button>
                                    <Button Grid.Row="1"
                                            IsTabStop="False"
                                            Padding="1"
                                            Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=DownCommand, Mode=OneWay}">
                                        <Image Source="/MM.Toolkit;component/Resources/Arrow.Bullet.Down.32x32.png" />
                                    </Button>
                                </Grid>
                            </Grid>
                            <Popup x:Name="PART_CalendarPopup"
                                   VerticalAlignment="Bottom"
                                   IsOpen="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=CalendarPopupIsOpen, Mode=OneWay}">
                                <sdk:Calendar SelectedDate="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=SelectedCalendarDateTime, Mode=TwoWay}"
                                              IsTodayHighlighted="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=IsTodayHighlighted, Mode=OneWay}"
                                              FirstDayOfWeek="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=FirstDayOfWeek, Mode=OneWay}"
                                              SelectionMode="SingleDate" />
                            </Popup>
                            <Popup x:Name="PART_TimePopup"
                                   VerticalAlignment="Bottom"
                                   IsOpen="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=TimePopupIsOpen, Mode=OneWay}">
                                <ListBox ItemsSource="{TemplateBinding Times}"
                                         SelectedItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=SelectedTime, Mode=TwoWay}"
                                         Width="100" Height="250">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Margin="10,2,2,2"
                                                       Text="{Binding Path=., Mode=OneWay, Converter={StaticResource DateTimeFormatConverter}, ConverterParameter='time'}"/>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Popup>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>





    <!-- ####################################################################### -->
    <!-- #                                                                     # -->
    <!-- #                             SearchBox                               # -->
    <!-- #                                                                     # -->
    <!-- ####################################################################### -->
    <Style TargetType="local:SearchBox">
        <Setter Property="MinHeight" Value="20" />
        <Setter Property="Height" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:SearchBox">
                    <Border x:Name="PART_LayoutRootBorder"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_InnerGridBorder"
                                                                       Storyboard.TargetProperty="(Border.BorderThickness)"
                                                                       Duration="0">
                                            <ObjectAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="1" />
                                            </ObjectAnimationUsingKeyFrames.KeyFrames>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_InnerGridBorder"
                                                                       Storyboard.TargetProperty="(Border.BorderThickness)"
                                                                       Duration="0">
                                            <ObjectAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="1" />
                                            </ObjectAnimationUsingKeyFrames.KeyFrames>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="PART_LayoutRoot">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="25" />
                                </Grid.ColumnDefinitions>
                                <Grid Grid.Column="0">
                                    <Border Background="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=IsReadOnly, Mode=OneWay, Converter={StaticResource BoxBackgroundConverter}, ConverterParameter='invert'}"
                                            Padding="2"
                                            BorderThickness="1"
                                            BorderBrush="{StaticResource TextBoxBorderBrush}" />
                                    <Border x:Name="PART_InnerGridBorder"
                                            Margin="1"
                                            BorderThickness="0"
                                            BorderBrush="{StaticResource TextBoxSelectedBorderBrush}"/>
                                    <ContentPresenter x:Name="PART_ContentPresenter"
                                                      Content="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=SelectedItem, Mode=TwoWay}"
                                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                                      Cursor="IBeam" />
                                </Grid>
                                <Button Grid.Column="1"
                                        IsTabStop="False"
                                        Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PopupClickCommand, Mode=OneWay}">
                                    <Image Source="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PopupIsVisible, Mode=OneWay, Converter={StaticResource PopupShowingImageConverter}}" />
                                </Button>
                            </Grid>
                            <Popup x:Name="PART_Popup"
                                   VerticalAlignment="Bottom"
                                   IsOpen="{TemplateBinding PopupIsVisible}">
                                <Grid Width="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PopupWidth, Mode=OneWay}"
                                      Height="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PopupHeight, Mode=OneWay}"
                                      MaxWidth="800"
                                      MaxHeight="400">
                                    <Grid.Effect>
                                        <DropShadowEffect Color="Black" Direction="225" Opacity=".5" ShadowDepth="5" BlurRadius="10" />
                                    </Grid.Effect>
                                    <Border BorderBrush="LightSlateGray" BorderThickness="1" CornerRadius="3" Background="WhiteSmoke" />
                                    <kit:DockPanel>
                                        <Button kit:DockPanel.Dock="Top"
                                                Height="22"
                                                IsTabStop="False"
                                                Background="Transparent"
                                                Content="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ClearContent, Mode=OneWay}"
                                                HorizontalContentAlignment="Center"
                                                VerticalContentAlignment="Center"
                                                Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ClearClickCommand, Mode=OneWay}"
                                                Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ClearContentButtonIsVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibilityTypeConverter}}" />
                                        <ContentPresenter x:Name="PART_ExtendedFilterTemplate"
                                                          kit:DockPanel.Dock="Top"
                                                          Content="{TemplateBinding ExtendedFilter}" />
                                        <StackPanel kit:DockPanel.Dock="Top" Orientation="Vertical">
                                            <TextBlock Margin="2,0,2,0"
                                                       Text="{TemplateBinding SearchLabelText}" />
                                            <TextBox Name="PART_SearchTextBox"
                                                     Margin="2,0,2,0"
                                                     Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                                     IsReadOnly="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=IsSearching, Mode=OneWay}">
                                                <!--<int:Interaction.Behaviors>
                                                    <nscmn:TextBoxUpdateBehavior />
                                                </int:Interaction.Behaviors>-->
                                            </TextBox>
                                        </StackPanel>
                                        <Button kit:DockPanel.Dock="Bottom"
                                                Height="22"
                                                IsTabStop="False"
                                                Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=PopupClickCommand, Mode=OneWay}">
                                            <Image Source="/MM.Toolkit;component/Resources/Arrow.Bullet.Up.32x32.png" />
                                        </Button>
                                        <ListBox Name="PART_ListBox"
                                                 Background="Transparent"
                                                 BorderBrush="Transparent"
                                                 BorderThickness="0"
                                                 UseLayoutRounding="True"
                                                 Margin="0"
                                                 Padding="0"
                                                 ItemTemplate="{TemplateBinding ItemTemplate}"
                                                 ItemsSource="{TemplateBinding ItemsSource}"
                                                 SelectedItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=InternalSelectedItem, Mode=TwoWay}">
                                        </ListBox>
                                    </kit:DockPanel>
                                    <kit:BusyIndicator IsBusy="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=IsSearching, Mode=OneWay}"
                                                       BusyContent="Searching..." />
                                </Grid>
                            </Popup>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
